<?
session_start();
include('conn.php');
$custid = $_SESSION['custid'];
$bid = $_SESSION['bid'];
$fromdt=$_SESSION['fromdt'];
$todt=$_SESSION['todt'];
$subid=$_SESSION['subid'];

$date=$_SESSION['todt'];
$day= substr($date,0,2);
$month = substr($date,3,2);
$year = substr($date,6,4);
$todt=$year.'-'.$month.'-'.$day;

$date=$_SESSION['fromdt'];
$day= substr($date,0,2);
$month = substr($date,3,2);
$year = substr($date,6,4);
$fromdt=$year.'-'.$month.'-'.$day;

$qry1 = "SELECT A.trnid, A.custid, C.custdesc,  B.Sector, B.`Travel Date` , B.Basic, B.Tax, B.Admincharges, B.Basic + B.Tax + B.Admincharges  AS Total, B.`pax name` as paxname
FROM transactionmast A, transactiondetails B, customermast C
WHERE A.status=0
AND A.custid = C.custid
AND A.trnid = B.tranid
AND (
A.invoicenumber = ''
OR A.invoicenumber IS NULL
)  " ;

//$qry1 = "SELECT A.trndetid, B.custid, C.custdesc, A.Sector, A.`Travel Date`, A.Basic, A.Tax, A.Basic + A.Tax as Total FROM transactiondetails A, transactionmast B, customermast C where B.status = -2 and A.trndetid = B.trnid and B.custid = C.custid";
if ($custid >0)
{
	$qry1 =$qry1." and A.custid='".$custid."'";
}

if (($fromdt !='1-1-2014') and ($todt !='1-1-2014'))
{
	$qry1 =$qry1." and A.trndate between '".$fromdt."' AND '".$todt."' ";
}

//if ($bid >0)
//{
//	$qry1 =$qry1." and A.bid='".$bid."'";
//
//}
//if ($subid >0)
//{
//	$qry1 =$qry1." and A.subid='".$subid."'";
//}

$qry1 =$qry1." order by A.trnid desc";
 // echo $qry1;
 // return;
$qry = mysql_query($qry1);
$data = array();
while($rows = mysql_fetch_array($qry))
{
	$date = $rows['trndate'];
	$year= substr($date,0,4);
	$month = substr($date,5,2);
	$day = substr($date,8,2);
//	echo $day.'-'.$month.'-'.$year;
	$date = $day.'-'.$month.'-'.$year;
	$data[] = array("TrnNo"=>$rows['trnid'],
				  "custdesc"=>$rows['custdesc'],
				  "PaxName"=>$rows['paxname'],
				  "Sector"=>$rows['Sector'],
				  "TravelDate"=>$rows['Travel Date'],
				  "BaseFare"=>$rows['Basic'],
				  "Taxes"=>$rows['Tax'],
				  "Admincharges"=>$rows['Admincharges'],
				  "TotalAmount"=>$rows['Total']);
}
//echo $data;
echo json_encode($data);
?>
